package com.miyake.dsp.otdr;

import com.miyake.dsp.osa.lab.LabUiAnnotation;

public class OtdrImpulseResponseSetting {
	private FiberNode entryPoint;
	@LabUiAnnotation(caption="Smp. Freq.")
	private double frequency = 1e9;
	@LabUiAnnotation(caption="Distance Range")
	private double distanceRange;
	@LabUiAnnotation(caption="Wavelength")
	private double wavelength;
	
	public OtdrImpulseResponseSetting(double wavelength, double distance) {
		this.wavelength = wavelength;
		this.distanceRange = distance;		
	}
	
	public OtdrImpulseResponseSetting(double frequency, double wavelength, double distance) {
		this.frequency = frequency;
		this.wavelength = wavelength;
		this.distanceRange = distance;
	}

	public FiberNode getEntryPoint() {
		return entryPoint;
	}

	public void setEntryPoint(FiberNode entryPoint) {
		this.entryPoint = entryPoint;
	}

	public double getFrequency() {
		return frequency;
	}

	public void setFrequency(double frequency) {
		this.frequency = frequency;
	}

	public double getDistanceRange() {
		return distanceRange;
	}

	public void setDistanceRange(double distanceRange) {
		this.distanceRange = distanceRange;
	}

	public double getWavelength() {
		return wavelength;
	}

	public void setWavelength(double wavelength) {
		this.wavelength = wavelength;
	}
	
	public double[] getTrace() {
		//double res = 1.0/this.frequency * 3e8;
		double res = 1.0/this.frequency * 3e8 / 2.0;
		double[] ret = this.entryPoint.getImpulseResponse(1000.0, res);
		int point = (int)(this.distanceRange*1000.0 / res * 1.5);
		//int point = (int)(this.distanceRange*1000 / res);
		double[] tmp = new double[point];
		for (int i = 0; i < tmp.length; i++) {
			if (i < ret.length) {
				tmp[i] = ret[i];
			}
			else {
				tmp[i] = 0;
			}
		}
		                        
		return tmp;
	}
	
}
